DodoRunner.Canvas = (function($, _, app, easel){
var
    WIDTH = 1280,
    HEIGHT = 768,

    stage = undefined,

    paused = false,

    init = function() {
		var $canvas = $("<canvas width='" + WIDTH + "' height='" + HEIGHT + "'></canvas>");
		$("body").append($canvas);
		stage = new createjs.Stage($canvas[0]);
        update();
        onTick(function(){
            stage.sortChildren(function(a, b){
                return (a.z - b.z == 0 ? a.id - b.id : a.z - b.z);
            });
            // stage.x -= 5;
        });
    },

    togglePause = function(){
        paused = true;
    },

    update = function(dt){
        if(!paused) stage.update();
        requestAnimationFrame(update);
    },

    getCameraX = function(){
        return stage.x;
    },

    getCameraY = function(){
        return stage.y;
    },

    setCameraX = function(x){
        stage.x = x;
    },

    setCameraY = function(y){
        stage.y = y;
    },

    addChild = function(child){
        stage.addChild(child);
    },

    onTick = function(callback){
        stage.onTick = callback;
    }

    return {
        WIDTH : WIDTH,
        HEIGHT : HEIGHT,
        togglePause : togglePause,
        setCameraX : setCameraX,
        setCameraY : setCameraY,
        getCameraX : getCameraX,
        getCameraY : getCameraY,
    	init : init,
        onTick : onTick,
        addChild : addChild
    }

}(jQuery, _, DodoRunner, createjs));